home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung CD 2 (Tewi)(1994).iso
/
doc
/
mir
/
dosify.c
< prev
next >
Wrap
Text File
|
1992-07-02
|
6KB
|
187 lines
/*
* usage: dosify file_name[s]
*
* DOSIFY Replaces a UNIX-style file with a copy in which each line feed
* is preceded by one carriage return, and the file ends with
* one CTL-Z byte. Use this program on a file in which the MORE
* command produces a skewed listing that fails to go back to the
* left margin for new lines.
*
* input: Any printable ASCII text file[s].
*
* output: The same file, with the same name, with DOS conventional line
* ends and end of file.
*
* writeup: MIR TUTORIAL ONE, topic 5
*
* Written: Douglas Lowry Jan 09 92
* Modified: Douglas Lowry May 23 92 touch-up
* Copyright (C) 1992 Marpex Inc.
*
* The MIR (Mass Indexing and Retrieval) Tutorials explain detailed
* usage and co-ordination of the MIR family of programs to analyze,
* prepare and index databases (small through gigabyte size), and
* how to build integrated retrieval software around the MIR search
* engine. The fifth of the five MIR tutorial series explains how
* to extend indexing capability into leading edge search-related
* technologies. For more information, GO IBMPRO on CompuServe;
* MIR files are in the DBMS library. The same files are on the
* Canada Remote Systems BBS. A diskette copy of the Introduction
* is available by mail ($10 US... check, Visa or Mastercard);
* diskettes with Introduction, Tutorial ONE software and the
* shareware Tutorial ONE text cost $29. Shareware registration
* for a tutorial is also $29.
*
* E-mail...
* Compuserve 71431,1337
* Internet doug.lowry%canrem.com
* UUCP canrem!doug.lowry
* Others: doug.lowry@canrem.uucp
*
* FAX... 416 963-5677
*
* "Snail mail"... Douglas Lowry, Ph.D.
* Marpex Inc.
* 5334 Yonge Street, #1102
* North York, Ontario
* Canada M2N 6M2
*
* Related database consultation and preparation services are
* available through:
* Innotech Inc., 2001 Sheppard Avenue E., Suite #118,
* North York, Ontario Canada M2J 4Z7
* Tel. 416 492-3838 FAX 416 492-3843
*
* This program is free software; you may redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* (file 05LICENS) along with this program; if not, write to the
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
* USA.
*/
#include <stdio.h>
#define repeat for(;;)
typedef enum bool
{ FALSE = 0, TRUE = 1 } Bool ;
Bool process();
void Usage_() ;
char *Cmdname_() { return( "dosify" ) ; }
/*
* MAIN -
*/
main( argc, argv )
int argc;
char **argv;
{
FILE *fp_in, *fp_out ;
Bool okay ;
char fname[16],
c10 ;
int file ;
c10 = argv[1][0] ;
if( argc == 1 || c10 == '-' || c10 == '/' || c10 == '?' )
Usage_();
sprintf( fname, "%d.999", getpid() );
for( file = 1; file < argc ; file++ )
{
if(( fp_in = fopen( argv[ file ], "rb" )) == NULL )
{
fprintf( stderr, "Can't open file %s\n", argv[ file ] );
continue ;
}
if(( fp_out = fopen( fname, "wb" )) == NULL )
{
fprintf( stderr, "Can't open temporary file %s\n", fname );
fclose( fp_in ) ;
continue ;
}
fprintf( stderr, "Dosifying %s\n", argv[ file ] ) ;
okay = process( fp_in, fp_out ) ;
if( fclose( fp_in ) || fclose( fp_out ))
{
fprintf( stderr, "Problem closing %s\n", argv[ file ] );
okay = FALSE ;
}
if( okay )
{
unlink( argv[ file ] ) ;
if( rename( fname, argv[ file ] ))
fprintf( stderr, "File %s okay, but has temporary name %s\n",
argv[ file ], fname ) ;
else
fprintf( stderr, "\t\t...Completed okay.\n" ) ;
}
}
exit( 0 );
}
void
Usage_()
{
fprintf( stderr, "\nusage: %s file_name[s]\n\n\
Replaces a UNIX-style file with a copy in which each line feed\n\
is preceded by one carriage return, and the file ends with\n\
one CTL-Z byte. Use this program on a file in which the MORE\n\
command produces a skewed listing that fails to go back to the\n",
Cmdname_() );
fprintf( stderr, " left margin for new lines.\n\n\
input: Any printable ASCII text file[s].\n\n\
output: The same file, with the same name, with DOS conventional line\n\
ends and end of file.\n\n\
writeup: MIR TUTORIAL ONE, topic 5\n\n" ) ;
exit( 1 ) ;
}
/*
* PROCESS
*/
Bool
process( fp_in, fp_out )
FILE *fp_in, *fp_out ;
{
int ch ;
Bool foul_up ;
foul_up = FALSE ;
repeat
{
if(( ch = fgetc( fp_in )) == EOF )
{
if( feof( fp_in ))
break ;
}
if( ch == '\n' )
fputc( '\015', fp_out ) ;
if( ch != '\015' && ch != '\032' )
{
if( fputc( ch, fp_out ) != ch )
foul_up = TRUE ;
}
if( foul_up )
return( FALSE );
}
fputc( '\032', fp_out );
return( TRUE ) ;
}